<template>
    <div align="center">
        <h2>病房信息列表展示</h2>
        科室:<select v-model="pages.uid">
            <option value=-1>请选择</option>
            <option v-for="item in pbind" :key="item.tid" :value="item.tid">{{ item.tname }}</option>
        </select>
        病房号(病房名称):<input type="text" v-model="pages.roomName">
        <input type="button" value="查询" @click="ShowHouse">
        <input type="button" value="添加病房信息" @click="router.push('/AddHouseView')">
        <table class="table table-bordered" width="1000">
            <tbody>
                <tr align="center">
                    <td>病房号(病房名称)</td>
                    <td>所属科室</td>
                    <td>床位总数</td>
                    <td>状态</td>
                    <td>空闲床数量</td>
                    <td>是否满员</td>
                    <td>创建日期</td>
                    <td>操作(修改小状态)</td>
                </tr>
                <tr align="center" v-for="item in pdate.list" :key="item.roomId">
                <tr>{{ item.roomNumber }}</tr>
                <td>{{ item.tname }}</td>
                <td>{{ item.begNum }}</td>
                <td>{{ item.state == 1 ? "维修" : "启用" }}</td>
                <td>{{ item.kongNum }}</td>
                <td>{{ item.statess==0? "满员" : "未满"}}</td>
                <td>{{ item.strDate.substring(1, 10) }}</td>
                <td><input type="button" :value="item.state == 1 ? '启用' : '维修'" @click="updateState(item.id)"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';


const router = useRouter();
const route = useRoute();

let pdate = reactive({
    list: [],
    ss: 0
});
let pages = reactive({
    uid: -1,
    roomName: ""
})

onMounted(() => {
    Binds();
    ShowHouse();
})


const ShowHouse = () => {
    console.log(pages.uid);

    axios({
        url: '/api/Hotel/ShowHouse',
        method: 'get',
        params: pages
    }).then((res) => {
        console.log(res.data);
        Object.assign(pdate, res.data);
    })
}


let pbind = ref([]);

const Binds = () => {
    axios({
        url: "/api/Hotel/Binds",
        method: "get"
    }).then((res) => {
        pbind.value = res.data;

    })
}


const updateState = (id: any) => {
    axios({
        url: '/api/Hotel/UpdState',
        method: 'put',
        params: { uid: id }
    }).then((res) => {
        if (res.data > 0) {
            alert("变更小状态成功!!!");
            ShowHouse();
        } else {
            alert("!!!变更状态失败!!!");
            return;
        }
    })
}
</script>

<style scoped></style>